package org.secangkirkopipanas.gxtcore.server.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

import net.sf.hibernate4gwt.pojo.java5.LazyPojo;

import org.secangkirkopipanas.gxtcore.domain.ISystemLog;

@Entity
@Table(name = "sys_log")
public class SystemLog extends LazyPojo implements Serializable, ISystemLog {

	private static final long serialVersionUID = 1L;

	public static final byte LEVEL_INFO = 1;
	public static final byte LEVEL_WARNING = 2;
	public static final byte LEVEL_ERROR = 3;

	@Id
	@Column(name = "id", nullable = false, insertable = true, updatable = true)
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;

	@Column(name = "log_time", nullable = false, insertable = true, updatable = true)
	private Date date;

	@Column(name = "log_level", nullable = false, insertable = true, updatable = true)
	private int level;

	@Column(name = "app_name", length = 50, nullable = false, insertable = true, updatable = true)
	private String appName;

	@Column(name = "module_name", length = 50, nullable = false, insertable = true, updatable = true)
	private String moduleName;

	@Column(name = "username", length = 25, nullable = false, insertable = true, updatable = true)
	private String userName;

	@Column(name = "ip_address", length = 15, nullable = false, insertable = true, updatable = true)
	private String ipAddress;

	@Column(name = "description", length = 255, nullable = false, insertable = true, updatable = true)
	private String description;

	public SystemLog() {
		super();
	}

	public SystemLog(int level, String appName, String moduleName,
			String userName, String ipAddress, String description) {
		this(new Date(), level, appName, moduleName, userName, ipAddress,
				description);
	}

	public SystemLog(Date date, int level, String appName, String moduleName,
			String userName, String ipAddress, String description) {
		super();
		this.date = date;
		this.level = level;
		this.appName = appName;
		this.moduleName = moduleName;
		this.userName = userName;
		this.ipAddress = ipAddress;
		this.description = description;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public String getAppName() {
		return appName;
	}

	public void setAppName(String appName) {
		this.appName = appName;
	}

	public String getModuleName() {
		return moduleName;
	}

	public void setModuleName(String moduleName) {
		this.moduleName = moduleName;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getIpAddress() {
		return ipAddress;
	}

	public void setIpAddress(String ipAddress) {
		this.ipAddress = ipAddress;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String text) {
		this.description = text;
	}

	public String getLevelName() {
		String name = "";
		switch (level) {
		case LEVEL_INFO:
			name = "INFO";
			break;
		case LEVEL_WARNING:
			name = "WARNING";
			break;
		case LEVEL_ERROR:
			name = "ERROR";
			break;
		default:
			break;
		}
		return name;
	}

}
